package path;

import java.util.ArrayList;
import java.util.Iterator;

import processing.core.PApplet;
import shapes.Vertex;

public class DrawUpdatedLinePath implements PathDrawer{
	ArrayList vertexes;
	
	public DrawUpdatedLinePath() {
		vertexes = new ArrayList();
	}

	public void drawPath(Path path, PApplet pa) {
		Iterator i = vertexes.iterator();
		pa.noFill();
		pa.stroke(0, 255, 0);
		pa.beginShape();
		while(i.hasNext()){
			((Vertex)i.next()).draw(pa);
		}
		pa.endShape();
		
	}

	public void keyAdded(Path p) {
		vertexes.add(new Vertex(p.getKeyFrameByIndex(p.getSize()-1).getPosition()));
	}

	public void keysAdded(Path p, int size) {
		for(int i = p.getSize() - size; i < p.getSize(); i++){
			vertexes.add(new Vertex(p.getKeyFrameByIndex(i).getPosition()));
		}
	}

	public void keyRemoved(Path p, int i) {
		//System.out.println("Removing " + i + "...");
		vertexes.remove(i);
		//System.out.println("DrawerSize = " + vertexes.size());
		//System.out.println("PathSize = " + p.getSize());
	}

}
